﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using DFT.DB;
using DFT.Infos;

namespace DFT
{
    public partial class Statistics : System.Web.UI.Page
    {
        public Int32 total, noMale, noFemale, noMuslim, noMarried, noDivorcee, noAcademy, noMaster, noDoctorate;
        public Double pMale, pFemale, pMuslim, pMarried, pDivorcee, pAcademy, pMaster, pDoctorate;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                DataTable statisticsTable = new DataTable("statistics");
                if (DBManager.GetAllStatisticsUser(((UserInfo)Session["userInfo"]).UserId, ref statisticsTable))
                {
                    tst.DataSource = statisticsTable;
                    tst.DataBind();

                    total = Int32.Parse(statisticsTable.Select("Column='Total' And  Value='All'")[0]["Total"].ToString());
                    if (total > 0)
                    {
                        DataRow[] rows = new DataRow[0];
                        rows = statisticsTable.Select("Column='gender' And  Value='m'");
                        if (rows.Length > 0)
                        {
                            noMale = Int32.Parse(rows[0]["Total"].ToString());
                            pMale = (Double)noMale * 100 / total;
                        }
                        rows = statisticsTable.Select("Column='gender' And  Value='f'");
                        if (rows.Length > 0)
                        {
                            noFemale = Int32.Parse(rows[0]["Total"].ToString());
                            pFemale = (Double)noFemale * 100 / total;
                        }
                        rows = statisticsTable.Select("Column='religion' And  Value='a'");
                        if (rows.Length > 0)
                        {
                            noMuslim = Int32.Parse(rows[0]["Total"].ToString());
                            pMuslim = (Double)noMuslim * 100 / total;
                        }
                        rows = statisticsTable.Select("Column='socialStatus' And  Value='b'");
                        if (rows.Length > 0)
                        {
                            noMarried = Int32.Parse(rows[0]["Total"].ToString());
                            pMarried = (Double)noMarried * 100 / total;
                        }
                        rows = statisticsTable.Select("Column='socialStatus' And  Value='c'");
                        if (rows.Length > 0)
                        {
                            noDivorcee = Int32.Parse(rows[0]["Total"].ToString());
                            pDivorcee = (Double)noDivorcee * 100 / total;
                        }
                        rows = statisticsTable.Select("Column='acadimicQual' And  Value='e'");
                        if (rows.Length > 0)
                        {
                            noAcademy = Int32.Parse(rows[0]["Total"].ToString());
                            pAcademy = (Double)noAcademy * 100 / total;
                        }
                        rows = statisticsTable.Select("Column='acadimicQual' And  Value='f'");
                        if (rows.Length > 0)
                        {
                            noMaster = Int32.Parse(rows[0]["Total"].ToString());
                            pMaster = (Double)noMaster * 100 / total;
                        }
                        rows = statisticsTable.Select("Column='acadimicQual' And  Value='g'");
                        if (rows.Length > 0)
                        {
                            noDoctorate = Int32.Parse(rows[0]["Total"].ToString());
                            pDoctorate = (Double)noDoctorate * 100 / total;
                        }
                    }
                }
            }
        }
    }
}